import axios from 'axios'
import store from '../vuex/index'
import cookie from '../utils/cookie'

export default {
  login: function (data) {
    return this.request('post', '/api/login', data)
  },
  request: function (method, url, data) {
    var headers = {
      token: store.state.token || cookie.get('token')
    }
    return axios({
      method: method,
      url: window.apiHost + url,
      data: data,
      dataType: 'json',
      headers: headers
    }).then(function (response) {
      return response.data
    })
  },
  getUserInfo: function () {
    return this.request('get', '/my/profile')
  },
  register: function (data) {
    return this.request('post', '/api/register', data)
  },
  saveUser: function (data) {
    return this.request('put', '/my/profile', data)
  },
  getCosSignature: function () {
    return this.request('get', '/my/cos-signature')
  }
}
